package com.ruoyi.content.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.content.domain.Articles;
import com.ruoyi.content.service.IArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articles")
public class ArticlesController extends BaseController {

    @Autowired
    private IArticlesService articlesService;

    @GetMapping("/{articleId}")
    public Articles getArticle(@PathVariable Long articleId) {
        return articlesService.selectArticleById(articleId);
    }

    @GetMapping("/list")
    public TableDataInfo getArticles() {
        startPage();
        List<Articles> list = articlesService.selectArticleList();
        return getDataTable(list);
    }

    @PostMapping("/release")
    public AjaxResult addArticle(@RequestBody Articles articles) {
        int i = articlesService.insertArticle(articles);
        return success();
    }

    @PutMapping("/")
    public int updateArticle(@RequestBody Articles articles) {
        return articlesService.updateArticle(articles);
    }

    @DeleteMapping("/{articleId}")
    public int deleteArticle(@PathVariable Long articleId) {
        return articlesService.deleteArticleById(articleId);
    }
}